package bound

/**
  * UpperBound
  *
  * @author zhangyimin
  * @date 2018-09-19 下午3:54
  * @version 1.0
  */
class Vehicle {
  def driver() = {
    println("Driving")
  }
}


class Car extends Vehicle {
  override def driver(): Unit = {
    println("Caring")
  }
}

class Bike extends Vehicle {
  override def driver(): Unit = {
    println("Biking")
  }
}


object UpperBound {
  //定义函数 T必须是一种交通工具
  def takeVehicle[T <: Vehicle](vehicle: T) = {
    vehicle.driver()
  }

  //示例拼接字符串
  def addStr[T<:String](x:T,y:T)={println(x+y)}


  //隐式转换
  implicit def int2String(n:Int):String={n.toString}
  //使用视图界定的函数
  def addStr2[T<%String](x:T,y:T)={println(x+y)}


  def main(args: Array[String]): Unit = {
    var v:Vehicle=new Vehicle
    takeVehicle(v)

    var car:Car=new Car
    takeVehicle(car)

    var bike:Bike=new Bike
    takeVehicle(bike)

    addStr("xxxxx","yyyyyyyy")


    addStr2(100,200);

  }


}
